package com.zj.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用结果，服务断响应 的数据最终都会封装成此对象
 *
 * @author zzj
 * @date 2023/02/22
 */
@Data
public class Result<T> {
    private int code; //返回状态码 1表示成功 其他表示失败
    private String msg;//提示信息
    private T data; //数据
    private Map map = new HashMap();

    public static <T> Result<T> success(T obj){
        Result<T> result = new Result<T>();
        result.data = obj;
        result.code = 1;
        return result;
    }
    public static <T> Result<T> success(T obj,String msg){
        Result<T> result = new Result<T>();
        result.data = obj;
        result.msg = msg;
        result.code = 1;
        return result;
    }
    public static <T> Result<T> error(String msg){
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

    public Result<T> add(String key,Object value){
        this.map.put(key,value);
        return this;
    }

}
